package com.project.restaurant.thirdpart.dto;

import com.project.restaurant.common.dto.RestaurantDetailInfo;
import com.project.restaurant.pojo.Meal;
import com.project.restaurant.pojo.Order;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WXNativePayOrder {

    /**
     * 本项目的订单id与微信的支付凭证映射对应关系
     */
    @NotEmpty
    private String orderId;

    /**
     * 与该订单关联的产品id
     */
    @NotEmpty
    private String productId;

    /**
     * 付款金额
     */
    private int payAmount;

    /**
     * 微信支付时显示的支付订单的描述
     */
    @NotEmpty
    private String description;

    /**
     * 微信支付的过期时间，(微信支付默认30分钟，至少要2分钟)
     * 比如：orderExpirationTime的时间是2022/10/15 22:00:00
     *  则代表在2022/10/15 22:00:00时，过时
     *
     */
    @NotNull
    private LocalDateTime orderExpirationTime;

    /**
     * 支付成功后回调的url
     */
    @NotEmpty
    private String notifyUrl;

    public static WXNativePayOrder getWXNativePayOrder(Order order, Meal meal, RestaurantDetailInfo restaurantInfo,
                                                       LocalDateTime timeExpire){
        WXNativePayOrder wxNativePayOrder = new WXNativePayOrder();
        wxNativePayOrder.setOrderId(order.getOrderId().replaceAll("-",""))
                .setProductId(String.valueOf(meal.getMealId()))
                .setPayAmount(order.getTotalPrice())
                .setDescription(restaurantInfo.getRestaurantName())
                .setOrderExpirationTime(timeExpire)
                .setNotifyUrl("www.baidu.com");
        return wxNativePayOrder;
    }
}
